package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.ZApplicaionAudit;
import cn.stylefeng.guns.modular.system.mapper.ZApplicaionAuditMapper;
import cn.stylefeng.guns.modular.system.model.params.ZApplicaionAuditParam;
import cn.stylefeng.guns.modular.system.model.result.ZApplicaionAuditResult;
import  cn.stylefeng.guns.modular.system.service.ZApplicaionAuditService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 小飞
 * @since 2019-07-30
 */
@Service
public class ZApplicaionAuditServiceImpl extends ServiceImpl<ZApplicaionAuditMapper, ZApplicaionAudit> implements ZApplicaionAuditService {

    @Override
    public void add(ZApplicaionAuditParam param){
        ZApplicaionAudit entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ZApplicaionAuditParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ZApplicaionAuditParam param){
        ZApplicaionAudit oldEntity = getOldEntity(param);
        ZApplicaionAudit newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ZApplicaionAuditResult findBySpec(ZApplicaionAuditParam param){
        return null;
    }

    @Override
    public List<ZApplicaionAuditResult> findListBySpec(ZApplicaionAuditParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ZApplicaionAuditParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ZApplicaionAuditParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ZApplicaionAudit getOldEntity(ZApplicaionAuditParam param) {
        return this.getById(getKey(param));
    }

    private ZApplicaionAudit getEntity(ZApplicaionAuditParam param) {
        ZApplicaionAudit entity = new ZApplicaionAudit();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
